package com.kds.fxtool.config;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

import java.io.IOException;
import java.net.URL;

public class ResourceManager {
    
    // FXML 文件路径
    public static final String LOGIN_FXML = "/fxml/login.fxml";
    
    // CSS 文件路径
    public static final String LOGIN_CSS = "/styles/login.css";
    
    public static Parent loadFXML(String fxmlPath) throws IOException {
        URL fxmlUrl = ResourceManager.class.getResource(fxmlPath);
        if (fxmlUrl == null) {
            throw new IOException("无法找到 FXML 文件: " + fxmlPath);
        }
        FXMLLoader loader = new FXMLLoader(fxmlUrl);
        return loader.load();
    }
    
    public static String getCSS(String cssPath) {
        URL cssUrl = ResourceManager.class.getResource(cssPath);
        return cssUrl != null ? cssUrl.toExternalForm() : null;
    }
    
    public static void applyCSS(Parent node, String cssPath) {
        String css = getCSS(cssPath);
        if (css != null) {
            node.getStylesheets().add(css);
        }
    }
}